<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>主页面</title>
		<script type="text/javascript" src="js/axios.js"></script>
		<script type="text/javascript" src="js/vue.js"></script>
		<script type="text/javascript" src="js/qs.js"></script>
		<script type="text/javascript" src="js/common.js"></script>
		<link rel="stylesheet" href="element/theme-chalk/index.css">
		<script src="element/index.js"></script>
	</head>
	<style>
		.el-table .warning-row {
			background: oldlace;
		}

		.el-table .success-row {
			background: #f0f9eb;
		}

		* {
			text-align: center;
			line-height: 100px;
		}
	</style>
	<body>
		<div id="app">
			<el-row :gutter="20">
				<el-col :span="6" :offset="10">
					<div class="grid-content bg-purple">
						<h1 style="text-align: center">调查问卷系统</h1>
						<template>
							<el-table :data="tableData" style="width:500px" :show-header="false"
								:row-class-name="tableRowClassName" :ref="'chooseTable'"
								@current-change="handleCurrentChange">
								<el-table-column prop="selection" label="控制面板" width="400px">
								</el-table-column>
							</el-table>
						</template>
					</div>
				</el-col>
			</el-row>
		</div>
	</body>
	<script>
		new Vue({
			el: "#app",
			data() {
				return {
					tableData: [{
						selection: '创建调查问卷'
					}, {
						selection: '调查问卷'
					}, {
						selection: '查看调查问卷情况'
					}]
				}
			},
			methods: {
				tableRowClassName({
					row,
					rowIndex
				}) {
					if (rowIndex === 0) {
						return 'warning-row';
					} else if (rowIndex === 1) {
						return 'success-row';
					} else if (rowIndex === 2) {
						return 'warning-row';
					}
					return '';
				},
				handleCurrentChange(val) {
					this.currentRow = val;
					console.log(val.selection)
					if(val.selection=="创建调查问卷"){
						location.href = "create.html";
					}
					if(val.selection=="调查问卷"){
						location.href = "questionnaire.html";
					}
					if(val.selection=="查看调查问卷情况"){
						location.href = "check.html";
					}
				},
				//加载用户数据
				loaduser() {
					let _this = this;
					axios.get("/users/loginUser").then(function(res) {
						let result = res.data;
						console.log(result);
						if (result.success) {
							console.log("登陆成功")
						} else {
							alert(result.errMsg);
							location.href = "login.html";
						}
					});
				}
			},
			mounted() {
				let _this = this;
				_this.loaduser();
			}
		})
	</script>
</html>
